package com.fsquare.admin.common;

import org.broadleafcommerce.openadmin.web.form.entity.EntityForm;
import org.broadleafcommerce.openadmin.web.form.entity.Field;
import org.broadleafcommerce.openadmin.web.form.entity.FieldGroup;
import org.broadleafcommerce.openadmin.web.form.entity.Tab;

public class Utils {
	
	public static FieldGroup findGroupForField(EntityForm entityForm, String fieldName) {
        fieldName = entityForm.sanitizeFieldName(fieldName);
        for (Tab tab : entityForm.getTabs()) {
            for (FieldGroup fieldGroup : tab.getFieldGroups()) {
                for (Field field : fieldGroup.getFields()) {
                    if (field.getName().equals(fieldName)) {
                        return fieldGroup;
                    }
                }
            }
        }
        return null;
    }
}
